import mne
import os
from mne.minimum_norm import read_inverse_operator, apply_inverse_raw

study_dir = '/autofs/space/clive_001/users/adriana/GE_SVM'
subj = 'GE_24'
label_dir = '/autofs/space/clive_001/users/adriana/GE_SVM/GE_13/labels/correctResponseOnly_39_ROI/L_SPC_1-lh/original_divisions'
label_fnames = os.listdir(label_dir)
labels = [mne.read_label(label_dir + '/' +label_fname) for label_fname in label_fnames]

mne.set_log_level(False)

for label in labels:
	fname_inv = study_dir + '/' + subj + '/rawdata/' + subj + '_meg_eeg-inv.fif'
	fname_raw = study_dir + '/' + subj + '/rawdata/' + subj + '_B1_filtered_raw.fif'
	raw = mne.io.read_raw_fif(fname_raw) 
	inv = read_inverse_operator(fname_inv)
	snr = 1.0
	lambda2 = 1.0 / snr ** 2
	method = "dSPM"
	stc = apply_inverse_raw(raw, inv, lambda2, method, label, 0, 100)
	print(label.name, stc.data.size)
